// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require(CONFIG.BasePath + "js/enterprise/base");
    var router = require("../hash/pageRouter");
    var footer = require("../footer/footer_gray");
    var top = require("../top/top_white");
    var flag = false;
    var init = function(){
    	footer.init();
    	top.init("更改绑定手机号码");
    	$("#head").removeClass("none");
    	$("#main").removeClass("none");
    	$("#footer").removeClass("none");
    	router.init();
		initEvent(); 
    };
    
	var initEvent = function(){
		
		$("#main").on("change", "#current_password", function(){
			validatePhoneNum();
		});
		
		//绑定点击事件
		$("#main").on("click", "#validate_password_next", function(){
			validatePhoneNum();
			if(flag){
				validateAccountPassword();
			}
		});
    };
    
    //验证密码
    var validateAccountPassword = function(){
		var current_password = $("#current_password").val();
		base.fnAjax({
			action: "validateAccountPassword.json",
			async: false,
			oData: {
				sessionUuid: base.getData("sid"),
                password: current_password
            }, //传递参数
            fnSuccess: function(data) {
                if (data.status == 200) {
                	base.saveData("password", current_password);
                	router.route("updatePhone/update_phone_change.html?password="+current_password, true);
                } else {
                   base.alert(3,data.message);
                }
            }
		});
	};
    
    //验证是否输入密码
    var validatePhoneNum = function(str) {
    	var password = $("#current_password").val();
    	if(password==""||password==null){
    		flag=false;
    		 base.alert(2,"请输入密码！");
    	}else{
    		flag=true;
    		$('.error_info').css('visibility','hidden');
    	}
    }

    return {
        init:init
    };
});